package lamnhungoc.dao.impl;

import lamnhungoc.dao.KhachHangDao;
import lamnhungoc.pojo.KhachHang;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class KhachHangDaoImpl implements KhachHangDao {
	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public int createKhachHang(KhachHang kh) {
		return (Integer) sessionFactory.getCurrentSession().save(kh);
	}

	@Override
	public boolean isKhacHang(String username, String password) {
		Object object = sessionFactory.getCurrentSession().createQuery("From KhachHang where tenDangNhap = :userName and matKhau = :passWord")
		.setParameter("userName", username).setParameter("passWord", password).uniqueResult();
		return (object != null);
	}

}
